package com.example.flight.util;

import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author: leo
 * @date: 2021/7/2
 */
public class DateUtil {

    public static void main(String[] args) throws ParseException {
        System.out.println(isEffectiveDate("12:01"));
    }


    public static boolean isEffectiveDate(String param) throws ParseException {
        SimpleDateFormat sf = new SimpleDateFormat("HH:mm");
        Date nowTime = sf.parse(param);
        Date startTime = sf.parse("09:00");
        Date endTime = sf.parse("12:00");

        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return true;
        }

        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);

        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }
}
